<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    template="./templates/rpsTemplate.xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <p:growl id="growl" showDetail="true"/>
        <ui:include src="dialogs/review-dialog.xhtml"/>
        <h:form id="frm-manage-interview">
            <div class="content-box"><!-- Start Content Box -->
                <div class="content-box-header">
                    <h:panelGroup rendered="#{accountMB.hRGroup}">
                        <h3>Manage Interviews</h3>
                    </h:panelGroup>
                    <h:panelGroup rendered="#{accountMB.interviewer}">
                        <h3>Review Interviews</h3>
                    </h:panelGroup>
                    <h:commandButton image="resources/images/icons/search.png"
                                     title="Search"
                                     rendered="#{not calendarMB.search}"
                                     actionListener="#{calendarMB.setSearch(true)}">
                        <f:ajax execute="@this" render="@form"/>
                    </h:commandButton>
                    <div class="clear"></div>
                </div>

                <div class="content-box-content" style="margin: 0px auto;">
                    <div class="default-tab">
                        <div id="calendar_wrap" class="manage">
                            <h:panelGroup rendered="#{not calendarMB.search}">
                                <div class="title_bar">
                                    <h:commandLink actionListener="#{calendarMB.backMonth}">
                                        <div class="previous"></div>
                                        <f:ajax execute="@this" render="@form"/>
                                    </h:commandLink>
                                    <h:commandLink actionListener="#{calendarMB.nextMonth}">
                                        <div class="next"></div>
                                        <f:ajax execute="@this" render="@form"/>
                                    </h:commandLink>
                                    <h2 class="month">#{calendarMB.monthYearFormat(calendarMB.date)}</h2>
                                </div>
                            </h:panelGroup>
                            <h:panelGroup rendered="#{calendarMB.search}">
                                <div id="search-interview">
                                    <fieldset>
                                        <label>Started Time :</label>
                                        <p:calendar id="startedTime"
                                                    styleClass="text-input small-input remove small-date"
                                                    required="true"
                                                    requiredMessage="You must select time."
                                                    value="#{calendarMB.startTime}"
                                                    pattern="MM/dd/yyyy HH:mm">
                                            <p:ajax event="dateSelect"
                                                    listener="#{calendarMB.handleDateStart}"
                                                    update="@form" />
                                        </p:calendar>

                                        <label>Ended Time :</label>
                                        <p:calendar id="endedTime"
                                                    styleClass="text-input small-input remove small-date"
                                                    required="true"
                                                    requiredMessage="You must select time."
                                                    value="#{calendarMB.endTime}"
                                                    pattern="MM/dd/yyyy HH:mm">
                                            <p:ajax event="dateSelect"
                                                    listener="#{calendarMB.handleDateEnd}"
                                                    update="@form" />
                                        </p:calendar>

                                        <label>Status :</label>
                                        <h:selectOneMenu id="cboStatus"
                                                         value="#{calendarMB.status}"
                                                         styleClass="text-input small-input small-date">
                                            <f:selectItem itemLabel="All interviews"  itemValue="-1"/>
                                            <f:selectItem itemLabel="Not In Progress" itemValue="0"/>
                                            <f:selectItem itemLabel="Selected" itemValue="100" />
                                            <f:selectItem itemLabel="Rejected" itemValue="-100" />
                                            <f:selectItem itemLabel="Postpone" itemValue="99" />
                                            <f:selectItem itemLabel="Remove" itemValue="1" />
                                            <f:ajax execute="@this" render="@form"/>
                                        </h:selectOneMenu>

                                        <h:commandButton value="Cancel"
                                                         actionListener="#{calendarMB.setSearch(false)}"
                                                         styleClass="schedule button">
                                            <f:ajax execute="@this" render="@form"/>
                                        </h:commandButton>
                                    </fieldset>
                                </div>
                            </h:panelGroup>
                            <h3 class="msg">#{calendarMB.msgInterview}</h3>
                            <h:panelGroup id="list" rendered="#{not empty calendarMB.eventDates}">
                                <ui:repeat value="#{calendarMB.eventDates}" var="date">
                                    <div class="article">
                                        <div class="article-left">
                                            <p:commandLink title="#{calendarMB.titleFormat(date)}">
                                                <div class="cal_day day_red">
                                                    <div class="day_heading">#{calendarMB.dayInWeekFormat(date)}</div>
                                                    <div class="day_count">
                                                        <span class="event">#{interviewBean.msgEvent(date)}</span>
                                                    </div>
                                                    <h:panelGroup rendered="#{calendarMB.today(date)}">
                                                        <div class="day_number today">#{calendarMB.dayFormat(date)}</div>
                                                    </h:panelGroup>
                                                    <h:panelGroup rendered="#{!calendarMB.today(date)}">
                                                        <div class="day_number">#{calendarMB.dayFormat(date)}</div>
                                                    </h:panelGroup>
                                                </div>
                                            </p:commandLink>
                                        </div>
                                        <div class="article-main">
                                            <h:panelGroup 
                                                rendered="#{not empty manageInterviewBean.listInterviews(
                                                            calendarMB.search, date, calendarMB.status)}">
                                                <h:dataTable value="#{manageInterviewBean.interviews}"
                                                             var="interview"
                                                             columnClasses="col-30,col-100,col-120,col-150,col-120,col-30 col-center,col-center">
                                                    <h:column>
                                                        <h:graphicImage value="resources/images/other/not_in_progress.png"
                                                                        rendered="#{interview.status == 0}"
                                                                        title="Not In Progress"/>
                                                        <h:graphicImage value="resources/images/other/select.png"
                                                                        rendered="#{interview.status == 100}"
                                                                        title="Selected"/>
                                                        <h:graphicImage value="resources/images/other/reject.png"
                                                                        rendered="#{interview.status == -100}"
                                                                        title="Rejected"/>
                                                        <h:graphicImage value="resources/images/other/postpone.png"
                                                                        rendered="#{interview.status == 99}"
                                                                        title="Postpone"/>
                                                        <h:graphicImage value="resources/images/other/remove.png"
                                                                        rendered="#{interview.status == 1}"
                                                                        title="Remove"/>
                                                    </h:column>
                                                    <h:column>
                                                        <f:facet name="header">Time</f:facet>
                                                        #{calendarMB.timeFormat(interview.startedTime)}
                                                        to #{calendarMB.timeFormat(interview.endedTime)}
                                                    </h:column>
                                                    <h:column>
                                                        <f:facet name="header">Interviewer</f:facet>
                                                        #{interview.employee.firstName} #{interview.employee.lastName}
                                                    </h:column>
                                                    <h:column>
                                                        <f:facet name="header">Vacancy</f:facet>
                                                        #{interview.vacancy.title}
                                                    </h:column>
                                                    <h:column>
                                                        <f:facet name="header">Applicant</f:facet>
                                                        #{interview.applicant.firstName} #{interview.applicant.lastName}
                                                    </h:column>
                                                    <h:column>
                                                        <f:facet name="header">Review</f:facet>
                                                        <h:graphicImage value="resources/images/other/selected.png"
                                                                        rendered="#{interview.AVStatus == 100}"
                                                                        title="Selected"/>
                                                        <h:graphicImage value="resources/images/other/rejected.png"
                                                                        rendered="#{interview.AVStatus == -100}"
                                                                        title="Rejected"/>
                                                        <h:graphicImage value="resources/images/other/in_progress.png"
                                                                        rendered="#{interview.AVStatus == 99}"
                                                                        title="In Progress"/>
                                                        <h:graphicImage value="resources/images/other/not_required.png"
                                                                        rendered="#{interview.AVStatus == 1}"
                                                                        title="Not required"/>
                                                    </h:column>
                                                    <h:column>
                                                        <f:facet name="header">Action</f:facet>
                                                        <h:panelGroup rendered="#{interview.status != 1}">
                                                            <h:panelGroup rendered="#{accountMB.hRGroup}">
                                                                <h:panelGroup rendered="#{interview.AVStatus == 99}">
                                                                    <h:button outcome="processing-interview.xhtml"
                                                                              title="Change time"
                                                                              image="resources/images/icons/clock.png"
                                                                              rendered="#{interview.status!=-100}">
                                                                        <f:param name="id" value="#{interview.interviewID}"/>
                                                                        <f:param name="type" value="time"/>
                                                                    </h:button>
                                                                    <h:button outcome="processing-interview.xhtml"
                                                                              title="Reschedule"
                                                                              image="resources/images/icons/refresh.png"
                                                                              rendered="#{interview.status==-100}">
                                                                        <f:param name="id" value="#{interview.interviewID}"/>
                                                                        <f:param name="type" value="info"/>
                                                                    </h:button>
                                                                    <h:commandButton image="resources/images/icons/unlock.png"
                                                                                     title="Reopen"
                                                                                     rendered="#{interview.status == 99}"
                                                                                     actionListener="#{manageInterviewBean.reopen()}">
                                                                        <f:param name="id" value="#{interview.interviewID}"/>
                                                                        <f:ajax execute="@this" render="@form :growl"/>
                                                                    </h:commandButton>
                                                                    <h:commandButton image="resources/images/icons/lock.png"
                                                                                     title="Postpone"
                                                                                     rendered="#{interview.status != 99}"
                                                                                     actionListener="#{manageInterviewBean.postpone()}">
                                                                        <f:param name="id" value="#{interview.interviewID}"/>
                                                                        <f:ajax execute="@this" render="@form :growl"/>
                                                                    </h:commandButton>
                                                                </h:panelGroup>
                                                                <h:commandButton image="resources/images/icons/trash.png"
                                                                                 title="Remove"
                                                                                 onclick="return remove();"
                                                                                 actionListener="#{manageInterviewBean.remove()}">
                                                                    <f:param name="id" value="#{interview.interviewID}"/>
                                                                    <f:ajax execute="@this" render="@form :growl"/>
                                                                </h:commandButton>
                                                            </h:panelGroup>
                                                            <h:panelGroup rendered="#{accountMB.interviewer and interview.AVStatus==99}">
                                                                <h:button outcome="processing-interview.xhtml"
                                                                          title="Change time"
                                                                          image="resources/images/icons/clock.png"
                                                                          rendered="#{interview.status!=99}">
                                                                    <f:param name="id" value="#{interview.interviewID}"/>
                                                                    <f:param name="type" value="time"/>
                                                                </h:button>
                                                                <h:button outcome="info.xhtml"
                                                                          title="Information"
                                                                          image="resources/images/icons/info.png"/>
                                                                <h:commandButton image="resources/images/icons/review.png"
                                                                                 onclick="dlg.show();"
                                                                                 title="Review"
                                                                                 rendered="#{interview.status==100}">
                                                                    <f:param name="id" value="#{interview.interviewID}"/>
                                                                    <f:ajax execute="@this" render=":frm-review"/>
                                                                </h:commandButton>
                                                            </h:panelGroup>
                                                        </h:panelGroup>
                                                    </h:column>
                                                </h:dataTable>
                                            </h:panelGroup>
                                        </div>
                                    </div>
                                </ui:repeat>
                            </h:panelGroup>
                        </div>
                    </div> <!-- End #tab3 -->
                </div> <!-- End .content-box-content -->
            </div> <!-- End .content-box -->
            <script type="text/javascript">
                function remove(){
                    return confirm("The interview will be removed and will not be REOPEN or POSTPONE by anyway.\n\
\n\
Are you sure to removed this interview?");
                }

                $('.remove input').removeClass('ui-inputfield');
            </script>
        </h:form>
    </ui:define>

</ui:composition>
